package com.braveman.im.ui.activity.message;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.braveman.im.R;
import com.braveman.im.bean.ChangeGroupAndComplate;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.ui.weiget.ClearEditText;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

import retrofit2.Call;
import retrofit2.Response;

public class ChangeCompanyInfoActivity extends BaseActivity {
    private ClearEditText mCetChangeInfo;
    private String title;
    private String groupId;
    private int type;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText(title).setLeftBtnIcon(R.mipmap.back_black).addActions(new TitleBarView.Action("保存") {
            @Override
            public void performAction(View view) {
                ChangeGroupAndComplate changeGroupAndComplate = new ChangeGroupAndComplate();
                String data = mCetChangeInfo.getText().toString().trim();
                if (TextUtils.isEmpty(data)) {
                    UIUtils.showToast(title + "不能为空,请重新输入");
                    return;
                }
                switch (type) {
                    case 1://单位名称
                        changeGroupAndComplate.corpName = data;
                        break;
                    case 2://单位介绍
                        changeGroupAndComplate.corpDescription = data;
                        break;
                    case 3://欢迎语
                        changeGroupAndComplate.welcomeTips = data;
                        break;
                }
                ApiManager.getApi().changeComplateInfo(groupId, changeGroupAndComplate).enqueue(new NetCallBack<ChangeGroupAndComplate>() {
                    @Override
                    protected void onSuccess(Call<ChangeGroupAndComplate> call, Response<ChangeGroupAndComplate> response) {
                        if (response != null) {
                            UIUtils.showToast("信息修改成功");
                            Intent intent = new Intent();
                            String changInfo = mCetChangeInfo.getText().toString().trim();
                            intent.putExtra("change_info", changInfo);
                            setResult(RESULT_OK, intent);
                            ActivityUtils.finishActivity(ChangeCompanyInfoActivity.this);
                            ActivityUtils.finishActivity(ChangeCompanyInfoActivity.this);
                        }
                    }
                });



            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        title = callIntent.getStringExtra("title");
        groupId = callIntent.getStringExtra("groupId");
        type = callIntent.getIntExtra("type", -1);
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_change_company_info;
    }

    @Override
    protected void initChildView() {
        mCetChangeInfo = (ClearEditText) findViewById(R.id.cet_change_info);

    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {

    }
}
